<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
function createrange() {
	var range1 = document.createRange(),
		range2 = document.createRange();
	var h1 = document.getElementsByTagName("h1")[0];
	var h2 = document.getElementsByTagName("h2")[0];
	range1.selectNodeContents(h1);
	range2.selectNodeContents(h2);
	range1.setEndAfter(h2.lastChild);
	console.log( range1.compareBoundaryPoints(Range.START_TO_START, range2) );
	console.log( range1.compareBoundaryPoints(Range.END_TO_END, range2));		
}
</script>
</head>

<body>
<section id="wrap">
    <article id="main">
        <h1>游子吟</h1>
        <h2>孟郊</h2>
        <p>慈母手中线，游子身上衣。临行密密缝，意恐迟迟归。谁言寸草心，报得三春晖。</p>
    </article>
    <header>
        <input type="button" value="折叠范围" onclick="createrange()" />
    </header>
</section>
</body>
</html>
